package commonClass;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import Modle.disease.Disease;

import android.util.Log;

public class ADAQueryDiseaseInfoByDiseaseIDAction implements IAnimalDoctorAction {

	
	@Override	
	public String object2json(ArrayList<Object> list) {
		
		String jsonString="";
		jsonString = "diseaseID=" + (String) list.get(0);
//	
//		Integer j = (Integer) list.get(0);
		
		return jsonString;
	}

	@Override
	public ArrayList<Object>  json2object(String json) {

		ArrayList<Object> list = new ArrayList<Object>();

//		Integer i = new Integer(10);
//		list.add(i);
		if (!jsonIsData(json))
			return null;
		list = getListFromJson(json);
		return list;
	}
	private ArrayList<Object> getListFromJson(String json) {

		ArrayList<Object> list = new ArrayList<Object>();

		org.json.JSONArray jsonObjs = null;
		try {
			jsonObjs = new JSONObject(json).getJSONArray("disease");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		String segJson = "";
		Log.v("000000", "getListFromJson");
		
	
		
		for (int i = 0; i < jsonObjs.length(); i++) {
			JSONObject jsonObj = ((JSONObject) jsonObjs.opt(i));
//			segJson = new Gson().toJson(jsonObj);
			
			
			Disease obj = json2SymptomsCategorie1(jsonObj);
			
			list.add(obj);
		}

		return list;

		/*
		 * int id = jsonObj.getInt("id"); String name =
		 * jsonObj.getString("name"); String gender =
		 * jsonObj.getString("gender"); s += "ID号"+id + ", 姓名：" + name + ",性别："
		 * + gender+ "\n" ;
		 */

	}
	private boolean jsonIsData(String json) {

		JSONObject jsonObj;
		String result = "";
		try {
			jsonObj = new JSONObject(json);
			result = jsonObj.getString("code");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return (result.equals("success"));
	}
	
	private Disease json2SymptomsCategorie1(JSONObject jsonObj) {
		Disease obj = new Disease();

		// new Gson().fromJson(segJson,SymptomsCategorie.class);

		try {
//			JSONObject jsonObj = new JSONObject(segJson);


			
			obj.setClinicalDiagnose(jsonObj.getString("clinicalDiagnose"));
			obj.setVulnerableGroups(jsonObj.getString("vulnerableGroups"));
			obj.setAnimalDiseaseCategorieName(jsonObj.getString("animalDiseaseCategorieName"));
			obj.setAnimalID(jsonObj.getString("animalID"));
			obj.setPathologicalChange(jsonObj.getString("pathologicalChange"));
			obj.setAnimalDiseaseCategorieID(jsonObj.getString("animalDiseaseCategorieID"));
			obj.setAnimalName(jsonObj.getString("animalName"));
			obj.setClinicalSymptoms(jsonObj.getString("clinicalSymptoms"));
			obj.setPathogen(jsonObj.getString("pathogen"));
			obj.setPreventionMeasures(jsonObj.getString("preventionMeasures"));
			obj.setDiseaseChineseName(jsonObj.getString("diseaseChineseName"));
			obj.setDiseaseID(jsonObj.getString("diseaseID"));
			obj.setTherapeuticSchedule(jsonObj.getString("therapeuticSchedule"));
			obj.setAttacklCharacters(jsonObj.getString("attacklCharacters"));
/*		obj.setAnimalID(jsonObj.getString("animalID"));
			obj.setAnimalName((jsonObj.getString("animalName")));
			obj.setIsAnatomySymptoms((jsonObj.getInt("isAnatomySymptoms")));
			obj.setIsBasicSymptom((jsonObj.getInt("isBasicSymptom")));
			obj.setSymptomsCategorieID((jsonObj
					.getString("symptomsCategorieID")));
			obj.setSymptomsCategorieName((jsonObj
					.getString("symptomsCategorieName")));*/

			Log.v("000000", "SymptomsCategorie:" + obj.toString());
			return obj;
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;

	}
	

}
